<?php
/**
 * This file is part of Hyperf Mall.
 *
 * @link     https://gitee.com/scwlkj/hyperf_mall
 * @contact  hyperf_mall@163.com
 */

namespace App\JsonRpc;

use App\Constants\Goods;
use App\Exception\BaseException;
use App\JsonRpc\Interfaces\BrandServiceInterface;
use Hyperf\RpcServer\Annotation\RpcService;
use App\Repository\BrandRepository;
use Hyperf\Di\Annotation\Inject;

/**
 * @RpcService(name="Goods::BrandService", protocol="jsonrpc", server="jsonrpc")
 */
class BrandService extends BaseService implements BrandServiceInterface
{

    public function init()
    {
        $this->repository = BrandRepository::getInstance();
    }

    /**
     * Notes: 添加品牌
     * Author: Bruce.z
     * DateTime: 2021/12/22 20:17
     * @param array $data
     * @return \App\Model\BaseModel|\Hyperf\Database\Model\Model
     * @throws BaseException
     */
    public function add(array $data)
    {
        $one = $this->repository->getOne(['name'=>$data['name']]);
        if(count($one)){
            throw new BaseException(BaseException::BASE_ERROR, '品牌名称已存在');
        }
        return $this->repository->baseAdd($data);
    }
}
